#include <string>
#include <algorithm>
#include "CommandLineParser.h"
#include "CommandDefine.h"

using namespace std;
using namespace gitstore;

const string keys =
        "{help h           |                     | print this message}"
        "{@operation       |                     |  operation}"
        "{dataset d        |                     | dataset name}"
        "{branch b         |                     | branch name}"
        "{branch_note o    |                     | branch note}"
        "{new_branch n     |                     | new branch name}"
        "{version s        |                     | version hash}"
        "{refer_version r  |                     | refer version hash}"
        "{revision i       |                     | revision}"
        "{key k            |                     | key name}"
        "{value v          |                     | value}"
        "{type t           |       0             | dataset type}"
        "{size i           |                     | value size}"
        "{host h           |       127.0.0.1     | host}"
        "{port p           |       9008          | port}";



int main(int argc, char *argv[]) {
    CommandLineParser parser(argc, argv, keys);
    auto operation = parser.get<string>(0);
    transform(operation.begin(), operation.end(), operation.begin(), ::toupper);
    if ( operation.compare("CREATE_DATASET") == 0 ) {
        createDataset(&parser);
    } else if ( operation.compare("LIST_DATASET") == 0 ) {
        listDataset(&parser);
    } else if ( operation.compare("LIST_DATASET_BRANCHES") == 0 ) {
        listDatasetBranches(&parser);
    } else if ( operation.compare("LIST_DATASET_KEYS_BY_BRANCH") == 0 ) {
        listDatasetKeysByBranch(&parser);
    } else if ( operation.compare("LIST_DATASET_KEYS_BY_VERSION") == 0 ) {
        listDatasetKeysByVersion(&parser);
    } else if ( operation.compare("BRANCH_DATASET") == 0 ) {
        branchDataset(&parser);
    } else if ( operation.compare("PUT_KEY") == 0 ) {
        putKey(&parser);
    } else if ( operation.compare("GET_KEY_BY_BRANCH") == 0 ) {
        getKeyByBranch(&parser);
    } else if ( operation.compare("GET_KEY_BY_VERSION") == 0 ) {
        getKeyByVersion(&parser);
    } else if ( operation.compare("DIFF_KEYS_BY_BRANCH") == 0 ) {
        diffKeysByBranch(&parser);
    }else if ( operation.compare("DIFF_KEYS_BY_VERSION") == 0 ) {
        diffKeysByVersion(&parser);
    }
    //    GitStoreGrpc::RequestCreateObject request;
    //    request.set_name("obj5");
    //    request.set_note("");
    //    request.set_branch_name("master");
    //    request.set_branch_note("");
    //    request.set_commit_note("");
    //    request.set_type(0);
    //    request.set_value("haha1");
    //    request.set_size(5);
    //    GitStoreGrpc::ResponseCreateObject response;
    //    auto stub = GitStoreGrpc::GitStoreGrpcService::NewStub(grpc::CreateChannel("127.0.0.1:9008", grpc::InsecureChannelCredentials()));
    //    grpc::ClientContext context;
    //    stub->CreateObject(&context, request, &response);
    //    response.Clear();
}
